package com.example.demo1115.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo1115.entity.Book;
import com.example.demo1115.service.BookOneService;
import com.example.demo1115.vo.Result;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mp")
@Api(tags = "测试")
@CrossOrigin
public class BookController {
    @Autowired
    private BookOneService service;
    @PostMapping("findall")
    public Result findAll(@RequestParam(defaultValue = "1")Integer current,
                          @RequestParam(defaultValue = "5")Integer pageSize
    ) {
        Result all = service.findAll(current, pageSize);
        return all;
    }
    @PostMapping("insertone")
    public Result insertone(@RequestBody Book book) {
        System.out.println("book.toString() = " + book.toString());
        Result insertone = service.insertone(book.getIsbn(), book.getBookName(), book.getPrice());
        return insertone;
    }

    @PostMapping("updateone")
    public Result updateone(@RequestBody Book book) {
        System.out.println("book = " + book.toString());
        Result updateone = service.updateone(book.getIsbn(), book.getBookName(), book.getPrice());
        return updateone;
    }
    @PostMapping("deleteByisbn")
    public Result deleteByisbn(String isbn) {
        Result result = service.deleteByisbn(isbn);
        return result;
    }
}
